<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\blog\api\controller;

use app\api\BaseController;
use plugins\blog\api\model\Blog;
use plugins\blog\api\model\BlogComment;
use plugins\blog\api\model\BlogCollect;
/**
 * 统计
 */
class Count extends BaseController
{
    /**
     * 评论总数
     */
    public function comment() 
    {
        if ($this->request->isPost()) {
            $input = input('post.');
            $where = [];
            if (!empty($input['user_id'])) {
                $where[] = ['user_id', '=', $input['user_id']];
            }
            if (!empty($input['blog_id'])) {
                $where[] = ['blog_id', '=', $input['blog_id']];
            }
            $count = BlogComment::where($where)->count();
            return json(['status' => 'success', 'message' => '获取成功', 'count' => $count]);
        }
    }
    
    /**
     * 收藏总数
     */
    public function collect()
    {
        if ($this->request->isPost()) {
            $input = input('post.');
            $where = [];
            if (!empty($input['user_id'])) {
                $where[] = ['user_id', '=', $input['user_id']];
            }
            if (!empty($input['blog_id'])) {
                $where[] = ['blog_id', '=', $input['blog_id']];
            }
            $count = BlogCollect::where($where)->count();
            return json(['status' => 'success', 'message' => '获取成功', 'count' => $count]);
        }
    }
    
    /**
     * 发布总数
     */
    public function blog()
    {
        if ($this->request->isPost()) {
            $input = input('post.');
            $where = [];
            if (!empty($input['user_id'])) {
                $where[] = ['user_id', '=', $input['user_id']];
            }
            $count = Blog::where($where)->count();
            return json(['status' => 'success', 'message' => '获取成功', 'count' => $count]);
        }
    }
}